#! /user/bin/env python
#coding:utf-8

import pymongo
import time
import datetime


addr = "127.0.0.1:27017"

account = "admin"
password = "123456"

def collection_find():
        db_name = "yange_data"
        myclient = pymongo.MongoClient("mongodb://" + addr + "/")
        dblist = myclient.list_database_names()
        if db_name in dblist:
                mydb = myclient[db_name]
                mydb.authenticate(account, password)
                tblist = mydb.list_collection_names()
                doc = mydb["shisun_record"]
                data_list = doc.find()
                record_num = 0
                for data in data_list:
                        print data
                        record_num = record_num + 1
                print "记录条数:" , record_num -1

                last_update_time = doc.find({"_id":"last_update_time"})
                for x in last_update_time:
                        print "last_update_time:", x
                        timeStamp = x["end_time"]
                        timeArray = time.localtime(timeStamp)
                        otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
                        print(otherStyleTime)

collection_find()
